#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "operate.h"
#include "menu.h"
#include "myDatatype.h"

/*超市管理系统页面主菜单*/
void Menu(struct Node *supPhead, struct Node *comPhead, struct Node *staPhead, struct Node *masterPurPhead, struct Node *detailPurPhead)
{
	int flagMenu = 0;/*菜单循环结束控制器*/
	char option[20];
	
	while (flagMenu == 0)
	{
		system("cls");
		printf("\n\t\t---------------[超市进存销管理系统]---------------");
		printf("\n\t\t\t\t1 、管理员用户登录");
		printf("\n\t\t\t\t2 、普通用户登录 ");
		printf("\n\t\t\t\t0 、退出管理系统 ");
		printf("\n\t\t--------------------------------------------------");
		
		printf("\n\t\t请输入(0 - 2):");
		gets(option);
		
		if (strcmp(option, "0") == 0)
		{
			printf("\n\t\t退出 [超市进存销管理系统] ！");
			flagMenu = 1;
			return;
		}
		else if (strcmp(option, "1") == 0)
		{
			MenuManager(supPhead, comPhead, staPhead, masterPurPhead, detailPurPhead);/*管理员用户*/
		}
		else if (strcmp(option, "2") == 0)
		{
			sta *pSta = MenuPersonLogIn(staPhead);	/*用户登录界面*/
			
			if (pSta != NULL)
			{
				MenuPerson(pSta, staPhead, comPhead, masterPurPhead, detailPurPhead);/*普通用户*/
			}
		}
		else
		{
			printf("\n\t\t输入无效，请重新输入！");
			printf("\n\n\t\t");
			system("pause");
		}
	}
}

/*管理员操作菜单*/
void MenuManager(struct Node *supPhead, struct Node *comPhead, struct Node *staPhead, struct Node *masterPurPhead, struct Node *detailPurPhead)
{
	int flagMenu = 0;/*菜单循环结束控制器*/
	char option[20];
	
	while (flagMenu == 0)
	{
		fflush(stdin);
		system("cls");
		printf("\n\t\t-------------------[管理员用户]-------------------");
		printf("\n\t\t\t\t1 、[供应商管理]");
		printf("\n\t\t\t\t2 、[商品管理]");
		printf("\n\t\t\t\t3 、[员工管理]");
		printf("\n\t\t\t\t4 、[采购管理]");
		printf("\n\t\t\t\t0 、返回[超市进存销管理系统]");
		printf("\n\t\t--------------------------------------------------");
		
		printf("\n\t\t请输入(0 - 4):");
		gets(option);
		
		if (strcmp(option, "0") == 0)
		{
			printf("\n\t\t返回 [超市进存销管理系统] ！");
			flagMenu = 1;
			printf("\n\n\t\t");
			system("pause");
		}
		else if (strcmp(option, "1") == 0)	/*供应商管理菜单*/
		{
			MenuSupplier(supPhead);			
		}
		else if (strcmp(option, "2") == 0)	/*商品管理菜单*/
		{
			MenuCommodity(comPhead);		
		}
		else if (strcmp(option, "3") == 0)	/*员工管理菜单*/
		{
			MenuStaff(staPhead);				
		}
		else if (strcmp(option, "4") == 0)	/*采购管理菜单*/
		{
			MenuPurchase(comPhead, staPhead, masterPurPhead, detailPurPhead);				
		}
		else
		{
			printf("\n\t\t输入无效，请重新输入！");
			printf("\n\n\t\t");
			system("pause");
		}
	}	
}

void MenuSupplier(struct Node *phead)/*供应商管理操作菜单*/
{
	int flagMenu = 0;/*菜单循环结束控制器*/
	char option[20];
	
	while (flagMenu == 0)
	{
		fflush(stdin);
		system("cls");
		printf("\n\t\t-----------------[供应商管理]---------------------");
		printf("\n\t\t\t\t1 、录入供应商数据");
		printf("\n\t\t\t\t2 、查询供应商信息");
		printf("\n\t\t\t\t3 、修改供应商信息");
		printf("\n\t\t\t\t4 、删除供应商数据");
		printf("\n\t\t\t\t0 、返回 [管理员用户] 菜单");
		printf("\n\t\t--------------------------------------------------");	
		
		printf("\n\t\t请输入(0 - 4):");
		gets(option);
		
		if (strcmp(option, "0") == 0)
		{
			printf("\n\t\t返回 [管理员用户] 菜单！");
			flagMenu = 1;
			printf("\n\n\t\t");
			system("pause");
		}
		else if (strcmp(option, "1") == 0)
		{
			while (1)
			{
				fflush(stdin);		
				char judge[10];		/*判断是否继续输入*/
				
				printf("\n\t\t提示：输入n或N结束输入，按其他键则继续输入...");					
				gets(judge);
						
				if (strcmp(judge, "n")==0 || strcmp(judge, "N")==0)
				{
					printf("\n\t\t输入完成!\n\t\t");
					system("pause");
					break;
				}
				else
				{
					phead = AddList(phead, InputSup);
				}
			}
		}
		else if (strcmp(option, "2") == 0)
		{
			Traversal(phead, ShowSup);		/*查询所有供应商信息*/
			printf("\n\n\t\t");
			system("pause");
		}
		else if (strcmp(option, "3") == 0)
		{
			MenuSupplierChange(phead);		/*修改数据*/
		}
		else if (strcmp(option, "4") == 0)
		{
			MenuSupplierDelete(phead);		/*删除数据*/
		}
		else
		{
			printf("\n\t\t输入无效，请重新输入！");
			printf("\n\n\t\t");
			system("pause");
		}
	}
}

void MenuSupplierChange(struct Node *phead)/*供应商管理修改操作菜单*/
{
	int flagMenu = 0;/*菜单循环结束控制器*/
	char option[20];
	
	while (flagMenu == 0)
	{
		fflush(stdin);
		system("cls");
		printf("\n\t\t---------------修改供应商信息---------------");
		printf("\n\t\t 按1通过查找 [供应商编号] 进行修改信息操作");
		printf("\n\t\t 按2通过查找 [供应商名称] 进行修改信息操作");
		printf("\n\t\t 按3通过查找 [地址] 进行修改信息操作");
		printf("\n\t\t 按0返回 [供应商管理] 菜单");
		printf("\n\t\t--------------------------------------------");

		char confirm[10];	/*确定：判断是否为误操作*/
		int num;
		struct Node *p = NULL;
		struct Node *pnew = (struct Node *)malloc(sizeof(struct Node));
		
		p = phead->next;
		pnew->data = NULL;		
		
		printf("\n\t\t请输入(0 - 3):");
		gets(option);
		
		if (strcmp(option, "0") == 0)
		{
			printf("\n\t\t退出修改供应商信息功能！");
			flagMenu = 1;
			printf("\n\n\t\t");
			system("pause");
		}
		else if (strcmp(option, "1") == 0)
		{
			char varNo[CAPACITY];
						
			printf("\n\t\t输入 [供应商编号]:");
			scanf("%s", varNo);
						
			while (p != NULL)
			{
				num = CompareSupNo(p->data, varNo);
					
				if (num == 0)
				{
					break;
				}
							
				p = p->next;
			}
						
			if (p != NULL)
			{
				printf("\n\t\t成功通过 [供应商编号] 查找到该供应商！\n");
				printf("\n\t\t是否确定修改该供应商信息:");
				printf("\n\t\t按n或N退出修改操作，按其他键确定修改操作\n\t\t请输入：");
				fflush(stdin);
				gets(confirm);
				
				if (strcmp(confirm, "n")==0 || strcmp(confirm, "N")==0)
				{
					printf("\n\n\t\t退出修改操作！\n\t\t");
					system("pause");
					break;
				}
				else
				{
					pnew->data = InputSup();
					pnew->next = NULL;
								
					printf("\n\t\t修改后：\n");
					
					Change(phead, pnew, varNo, CompareSupNo);
					Traversal(phead, ShowSup);
							
					printf("\n\t\t修改完成！");
					printf("\n\n\t\t");
					system("pause");
				}
			}
			else 
			{
				printf("\n\t\t未找到该供应商！");
				printf("\n\t\t请重新选择操作！");
				printf("\n\n\t\t");
				system("pause");
			}	
		}
		else if (strcmp(option, "2") == 0)
		{
			char varName[CAPACITY];
						
			printf("\n\t\t输入 [供应商名称]:");
			scanf("%s", varName);
						
			while (p != NULL)
			{
				num = CompareSupName(p->data, varName);
							
				if (num == 0)
				{
					break;
				}
							
				p = p->next;
			}
						
			if (p != NULL)
			{
				printf("\n\t\t成功通过 [供应商名称] 查找到该供应商，接下来进行修改操作！\n");
				printf("\n\t\t是否确定修改该供应商信息:");
				printf("\n\t\t按n或N退出修改操作，按其他键确定修改操作\n\t\t请输入：");
				fflush(stdin);
				gets(confirm);
				
				if (strcmp(confirm, "n")==0 || strcmp(confirm, "N")==0)
				{
					printf("\n\n\t\t退出修改操作！\n\t\t");
					system("pause");
					break;
				}
				else
				{
					pnew->data = InputSup();
					pnew->next = NULL;
								
					printf("\n\t\t修改后：\n");
					
					Change(phead, pnew, varName, CompareSupName);
					Traversal(phead, ShowSup);
							
					printf("\n\t\t修改完成！");
					printf("\n\n\t\t");
					system("pause");
				}
			}
			else 
			{
				printf("\n\t\t未找到该供应商！");
				printf("\n\t\t请重新选择操作！");
				printf("\n\n\t\t");
				system("pause");
			}
		}
		else if (strcmp(option, "3") == 0)
		{
			char varAddress[CAPACITY];
						
			printf("\n\t\t输入 [地址]:");
			scanf("%s", varAddress);
						
			while (p != NULL)
			{
				num = CompareSupAddress(p->data, varAddress);
							
				if (num == 0)
				{
					break;
				}
							
				p = p->next;
			}
						
			if (p != NULL)
			{
				printf("\n\t\t成功通过 [地址] 查找到该供应商，接下来进行修改操作！\n");
				printf("\n\t\t是否确定修改该供应商信息:");
				printf("\n\t\t按n或N退出修改操作，按其他键确定修改操作\n\t\t请输入：");
				fflush(stdin);
				gets(confirm);
				
				if (strcmp(confirm, "n")==0 || strcmp(confirm, "N")==0)
				{
					printf("\n\n\t\t退出修改操作！\n\t\t");
					system("pause");
					break;
				}
				else
				{
					pnew->data = InputSup();
					pnew->next = NULL;
								
					printf("\n\t\t修改后：\n");
					
					Change(phead, pnew, varAddress, CompareSupAddress);
					Traversal(phead, ShowSup);
							
					printf("\n\t\t修改完成！");
					printf("\n\n\t\t");
					system("pause");
				}
			}
			else 
			{
				printf("\n\t\t未找到该供应商！");
				printf("\n\t\t请重新选择操作！");
				printf("\n\n\t\t");
				system("pause");
			}
		}
		else
		{
			printf("\n\t\t输入无效，请重新输入！");
			printf("\n\n\t\t");
			system("pause");
		}
	}
}

void MenuSupplierDelete(struct Node *phead)/*供应商管理删除操作菜单*/
{
	int flagMenu = 0;/*菜单循环结束控制器*/
	char option[20];
	
	while (flagMenu == 0)
	{
		fflush(stdin);
		system("cls");
		printf("\n\t\t---------------删除供应商信息---------------");
		printf("\n\t\t 按1通过查找 [供应商编号] 进行删除信息操作");
		printf("\n\t\t 按2通过查找 [供应商名称] 进行删除信息操作");
		printf("\n\t\t 按3通过查找 [地址] 进行删除信息操作");
		printf("\n\t\t 按0返回 [供应商管理] 菜单");
		printf("\n\t\t--------------------------------------------");
		
		char confirm[10];		/*确定：判断是否为误操作*/
		int num;
		struct Node *p = NULL;
		struct Node *q = (struct Node *)malloc(sizeof(struct Node));
		
		p = phead->next;
		q->data = NULL;
		
		printf("\n\t\t请输入(0 - 3):");
		gets(option);
		
		if (strcmp(option, "0") == 0)
		{
			printf("\n\t\t退出删除供应商信息功能！");
			flagMenu = 1;
			printf("\n\n\t\t");
			system("pause");
		}
		else if (strcmp(option, "1") == 0)
		{
			char varNo[CAPACITY];
			
			printf("\n\t\t输入 [供应商编号]:");
			scanf("%s", varNo);
						
			while (p != NULL)
			{
				num = CompareSupNo(p->data, varNo);
						
				if (num == 0)
				{
					break;
				}
							
				p = p->next;
			}
						
			if (p != NULL)
			{
				printf("\n\t\t成功通过 [供应商编号] 查找到该供应商！\n");
				printf("\n\t\t是否确定删除该供应商信息:");
				printf("\n\t\t按n或N退出删除操作，按其他键确定删除操作\n\t\t请输入：");
				fflush(stdin);
				gets(confirm);
				
				if (strcmp(confirm, "n")==0 || strcmp(confirm, "N")==0)
				{
					printf("\n\n\t\t退出删除操作！\n\t\t");
					system("pause");
					break;
				}
				else
				{
					q = Delete(phead, varNo, CompareSupNo);
					printf("\n\t\t被删除的数据：\n");
					ShowSup(q->data);
							
					printf("\n\t\t删除后：\n");
					Traversal(phead, ShowSup);
							
					printf("\n\t\t删除完成！");
					printf("\n\n\t\t");
					system("pause");
				}
			}
			else 
			{
				printf("\n\t\t未找到该供应商！");
				printf("\n\t\t请重新选择操作！");
				printf("\n\n\t\t");
				system("pause");
			}
		}
		else if (strcmp(option, "2") == 0)
		{
			char varName[CAPACITY];
						
			printf("\n\t\t输入 [供应商名称]:");
			scanf("%s", varName);
						
			while (p != NULL)
			{
				num = CompareSupName(p->data, varName);
							
				if (num == 0)
				{
					break;
				}
							
				p = p->next;
			}
						
			if (p != NULL)
			{
				printf("\n\t\t成功通过 [供应商名称] 查找到该供应商，接下来进行删除操作！\n");
				printf("\n\t\t是否确定删除该供应商信息:");
				printf("\n\t\t按n或N退出删除操作，按其他键确定删除操作\n\t\t请输入：");
				fflush(stdin);
				gets(confirm);
				
				if (strcmp(confirm, "n")==0 || strcmp(confirm, "N")==0)
				{
					printf("\n\n\t\t退出删除操作！\n\t\t");
					system("pause");
					break;
				}
				else
				{
					q = Delete(phead, varName, CompareSupName);
					printf("\n\t\t被删除的数据：\n");
					ShowSup(q->data);
							
					printf("\n\t\t删除后：\n");
					Traversal(phead, ShowSup);
							
					printf("\n\t\t删除完成！");
					printf("\n\n\t\t");
					system("pause");
				}
			}
			else 
			{
				printf("\n\t\t未找到该供应商！");
				printf("\n\t\t请重新选择操作！");
				printf("\n\n\t\t");
				system("pause");
			}
		}
		else if (strcmp(option, "3") == 0)
		{
			char varAddress[CAPACITY];
						
			printf("\n\t\t输入 [地址]:");
			scanf("%s", varAddress);
						
			while (p != NULL)
			{
				num = CompareSupAddress(p->data, varAddress);
							
				if (num == 0)
				{
					break;
				}
							
				p = p->next;
			}
						
			if (p != NULL)
			{
				printf("\n\t\t成功通过 [地址] 查找到该供应商，接下来进行删除操作！\n");
				printf("\n\t\t是否确定删除该供应商信息:");
				printf("\n\t\t按n或N退出删除操作，按其他键确定删除操作\n\t\t请输入：");
				fflush(stdin);
				gets(confirm);
				
				if (strcmp(confirm, "n")==0 || strcmp(confirm, "N")==0)
				{
					printf("\n\n\t\t退出删除操作！\n\t\t");
					system("pause");
					break;
				}
				else
				{
					q = Delete(phead, varAddress, CompareSupAddress);
					printf("\n\t\t被删除的数据：\n");
					ShowSup(q->data);
							
					printf("\n\t\t删除后：\n");
					Traversal(phead, ShowSup);
							
					printf("\n\t\t删除完成！");
					printf("\n\n\t\t");
					system("pause");
				}
			}
			else 
			{
				printf("\n\t\t未找到该供应商！");
				printf("\n\t\t请重新选择操作！");
				printf("\n\n\t\t");
				system("pause");
			}
		}
		else
		{
			printf("\n\t\t输入无效，请重新输入！");
			printf("\n\n\t\t");
			system("pause");
		}	
	}
}

void MenuCommodity(struct Node *phead)/*商品管理操作菜单*/
{
	int flagMenu = 0;/*菜单循环结束控制器*/
	char option[20];
	
	while (flagMenu == 0)
	{
		fflush(stdin);
		system("cls");
		printf("\n\t\t------------------[商品管理]----------------------");
		printf("\n\t\t\t\t1 、录入商品数据");
		printf("\n\t\t\t\t2 、查询商品信息");
		printf("\n\t\t\t\t3 、修改商品信息");
		printf("\n\t\t\t\t4 、删除商品数据");
		printf("\n\t\t\t\t0 、返回 [管理员用户] 菜单");
		printf("\n\t\t--------------------------------------------------");
		
		
		printf("\n\t\t请输入(0 - 4):");
		gets(option);
		
		if (strcmp(option, "0") == 0)
		{
			printf("\n\t\t返回 [管理员用户] 菜单！");
			flagMenu = 1;
			printf("\n\n\t\t");
			system("pause");
		}
		else if (strcmp(option, "1") == 0)
		{
			char judge[10];		/*判断是否继续输入*/
					
			while (1)
			{
				fflush(stdin);		
				printf("\n\t\t提示：输入n或N结束输入，按其他键则继续输入...");
				gets(judge);

				if (strcmp(judge, "n")==0 || strcmp(judge, "N")==0)
				{
					printf("\n\t\t输入完成!\n\t\t");
					system("pause");
					break;
				}
				else
				{
					phead = AddList(phead, InputCom);
				}
			}
		}
		else if (strcmp(option, "2") == 0)
		{
			Traversal(phead, ShowCom);	
			printf("\n\n\t\t");
			system("pause");
		}
		else if (strcmp(option, "3") == 0)
		{
			MenuCommodityChange(phead);
		}
		else if (strcmp(option, "4") == 0)
		{
			MenuCommodityDelete(phead);
		}
		else
		{
			printf("\n\t\t输入无效，请重新输入！");
			printf("\n\n\t\t");
			system("pause");
		}
	}
}

void MenuCommodityChange(struct Node *phead)/*商品管理修改操作菜单*/
{
	int flagMenu = 0;/*菜单循环结束控制器*/
	char option[20];
	
	while (flagMenu == 0)
	{
		fflush(stdin);
		system("cls");
		printf("\n\t\t----------------修改商品信息----------------");
		printf("\n\t\t 按1通过查找 [商品编号] 进行修改信息操作");
		printf("\n\t\t 按2通过查找 [商品名称] 进行修改信息操作");
		printf("\n\t\t 按0返回 [商品管理] 菜单");
		printf("\n\t\t--------------------------------------------");
		
		char confirm[10];		/*确定：判断是否为误操作*/
		int num;
		struct Node *p = NULL;
		struct Node *pnew = (struct Node *)malloc(sizeof(struct Node));
		
		p = phead->next;
		pnew->data = NULL;		
		
		printf("\n\t\t请输入(0 - 2):");
		gets(option);
		
		if (strcmp(option, "0") == 0)
		{
			printf("\n\t\t退出修改商品信息功能！");
			flagMenu = 1;
			printf("\n\n\t\t");
			system("pause");
		}
		else if (strcmp(option, "1") == 0)
		{
			char varNo[CAPACITY];
						
			printf("\n\t\t输入 [商品编号]:");
			scanf("%s", varNo);
						
			while (p != NULL)
			{
				num = CompareComNo(p->data, varNo);
							
				if (num == 0)
				{
					break;
				}
							
				p = p->next;
			}
						
			if (p != NULL)
			{
				printf("\n\t\t成功通过 [商品编号] 查找到该商品，接下来进行修改操作！\n");
				printf("\n\t\t是否确定修改该商品信息:");
				printf("\n\t\t按n或N退出修改操作，按其他键确定修改操作\n\t\t请输入：");
				fflush(stdin);
				gets(confirm);
				
				if (strcmp(confirm, "n")==0 || strcmp(confirm, "N")==0)
				{
					printf("\n\n\t\t退出修改操作！\n\t\t");
					system("pause");
					break;
				}
				else
				{
					pnew->data = InputCom();
					pnew->next = NULL;
								
					printf("\n\t\t修改后：\n");
					Change(phead, pnew, varNo, CompareComNo);
					Traversal(phead, ShowCom);
							
					printf("\n\t\t修改完成！");
					printf("\n\n\t\t");
					system("pause");
				}
			}
			else 
			{
				printf("\n\t\t未找到该商品！");
				printf("\n\t\t请重新选择操作！");
				printf("\n\n\t\t");
				system("pause");
			}	
		}
		else if (strcmp(option, "2") == 0)
		{
			char varName[CAPACITY];
						
			printf("\n\t\t输入 [商品名称]:");
			scanf("%s", varName);
					
			while (p != NULL)
			{
				num = CompareComName(p->data, varName);
					
				if (num == 0)
				{
					break;
				}
							
				p = p->next;
			}
						
			if (p != NULL)
			{
				printf("\n\t\t成功通过 [商品名称] 查找到该商品，接下来进行修改操作！\n");
				printf("\n\t\t是否确定修改该商品信息:");
				printf("\n\t\t按n或N退出修改操作，按其他键确定修改操作\n\t\t请输入：");
				fflush(stdin);
				gets(confirm);
				
				if (strcmp(confirm, "n")==0 || strcmp(confirm, "N")==0)
				{
					printf("\n\n\t\t退出修改操作！\n\t\t");
					system("pause");
					break;
				}
				else
				{
					pnew->data = InputCom();
					pnew->next = NULL;
								
					printf("\n\t\t修改后：\n");
					Change(phead, pnew, varName, CompareComName);
					Traversal(phead, ShowCom);
							
					printf("\n\t\t修改完成！");
					printf("\n\n\t\t");
					system("pause");
				}
			}
			else 
			{
				printf("\n\t\t未找到该商品！");
				printf("\n\t\t请重新选择操作！");
				printf("\n\n\t\t");
				system("pause");
			}
		}
		else
		{
			printf("\n\t\t输入无效，请重新输入！");
			printf("\n\n\t\t");
			system("pause");
		}
	}
}

void MenuCommodityDelete(struct Node *phead)/*商品管理删除操作菜单*/
{
	int flagMenu = 0;/*菜单循环结束控制器*/
	char option[20];
	
	while (flagMenu == 0)
	{
		fflush(stdin);
		system("cls");
		printf("\n\t\t----------------删除商品信息----------------");
		printf("\n\t\t 按1通过查找 [商品编号] 进行删除信息操作");
		printf("\n\t\t 按2通过查找 [商品名称] 进行删除信息操作");
		printf("\n\t\t 按0返回 [商品管理] 菜单");
		printf("\n\t\t--------------------------------------------");
		
		char confirm[10];		/*确定：判断是否为误操作*/
		int num;
		struct Node *p = NULL;
		struct Node *q = (struct Node *)malloc(sizeof(struct Node));
		
		p = phead->next;
		q->data = NULL;
		
		printf("\n\t\t请输入(0 - 3):");
		gets(option);
		
		if (strcmp(option, "0") == 0)
		{
			printf("\n\t\t退出删除商品信息功能！");
			flagMenu = 1;
			printf("\n\n\t\t");
			system("pause");
		}
		else if (strcmp(option, "1") == 0)
		{
			char varNo[CAPACITY];
						
			printf("\n\t\t输入 [商品编号]:");
			scanf("%s", varNo);
						
			while (p != NULL)
			{
				num = CompareComNo(p->data, varNo);
							
				if (num == 0)
				{
					break;
				}
							
				p = p->next;
			}
						
			if (p != NULL)
			{
				printf("\n\t\t成功通过 [商品编号] 查找到该商品，接下来进行删除操作！\n");
				printf("\n\t\t是否确定删除该商品信息:");
				printf("\n\t\t按n或N退出删除操作，按其他键确定删除操作\n\t\t请输入：");
				fflush(stdin);
				gets(confirm);
				
				if (strcmp(confirm, "n")==0 || strcmp(confirm, "N")==0)
				{
					printf("\n\n\t\t退出删除操作！\n\t\t");
					system("pause");
					break;
				}
				else
				{
					q = Delete(phead, varNo, CompareComNo);
					printf("\n\t\t被删除的数据：\n");
					ShowCom(q->data);
							
					printf("\n\t\t删除后：\n");
					Traversal(phead, ShowCom);
							
					printf("\n\t\t删除完成！");
					printf("\n\n\t\t");
					system("pause");
				}
			}
			else 
			{
				printf("\n\t\t未找到该商品！");
				printf("\n\t\t请重新选择操作！");
				printf("\n\n\t\t");
				system("pause");
			}	
		}
		else if (strcmp(option, "2") == 0)
		{
			char varName[CAPACITY];
						
			printf("\n\t\t输入 [商品名称]:");
			scanf("%s", varName);
						
			while (p != NULL)
			{
				num = CompareComName(p->data, varName);
							
				if (num == 0)
				{
					break;
				}
							
				p = p->next;
			}
						
			if (p != NULL)
			{
				printf("\n\t\t成功通过 [商品名称] 查找到该商品，接下来进行删除操作！\n\n");
				printf("\n\t\t是否确定删除该商品信息:");
				printf("\n\t\t按n或N退出删除操作，按其他键确定删除操作\n\t\t请输入：");
				fflush(stdin);
				gets(confirm);
				
				if (strcmp(confirm, "n")==0 || strcmp(confirm, "N")==0)
				{
					printf("\n\n\t\t退出删除操作！\n\t\t");
					system("pause");
					break;
				}
				else
				{
					q = Delete(phead, varName, CompareComName);
					printf("\n\t\t被删除的数据：\n");
					ShowCom(q->data);
							
					printf("\n\t\t删除后：\n");
					Traversal(phead, ShowCom);
							
					printf("\n\t\t删除完成！");
					printf("\n\n\t\t");
					system("pause");
				}
			}
			else 
			{
				printf("\n\t\t未找到该商品！");
				printf("\n\t\t请重新选择操作！");
				printf("\n\n\t\t");
				system("pause");
			}
			break;
		}
		else
		{
			printf("\n\t\t输入无效，请重新输入！");
			printf("\n\n\t\t");
			system("pause");
		}
	}
}

void MenuStaff(struct Node *phead)/*员工管理操作菜单*/
{
	int flagMenu = 0;/*菜单循环结束控制器*/
	char option[20];
	
	while (flagMenu == 0)
	{
		fflush(stdin);
		system("cls");
		printf("\n\t\t------------------[员工管理]----------------------");
		printf("\n\t\t\t\t1 、录入员工数据");
		printf("\n\t\t\t\t2 、查询员工信息");
		printf("\n\t\t\t\t3 、修改员工信息");
		printf("\n\t\t\t\t4 、删除员工数据");
		printf("\n\t\t\t\t0 、返回 [管理员用户] 菜单");
		printf("\n\t\t--------------------------------------------------");
		
		printf("\n\t\t请输入(0 - 4):");
		gets(option);
			
		if (strcmp(option, "0") == 0)
		{
			printf("\n\t\t返回 [管理员用户] 菜单！");
			flagMenu = 1;
			printf("\n\n\t\t");
			system("pause");
		}
		else if (strcmp(option, "1") == 0)
		{
			char judge[10];		/*判断是否继续输入*/
					
			while (1)
			{	
				fflush(stdin);	
				printf("\n\t\t提示：输入n或N结束输入，按其他键则继续输入...");
				gets(judge);

				if (strcmp(judge, "n")==0 || strcmp(judge, "N")==0)
				{
					printf("\n\t\t输入完成!\n\t\t");
					system("pause");
					break;
				}
				else
				{
					phead = AddList(phead, InputSta);
				}
			}
		}
		else if (strcmp(option, "2") == 0)
		{
			Traversal(phead, ShowSta);
			printf("\n\n\t\t");
			system("pause");
		}
		else if (strcmp(option, "3") == 0)
		{
			MenuStaffChange(phead);	
		}
		else if (strcmp(option, "4") == 0)
		{
			MenuStaffDelete(phead);
		}
		else 
		{
			printf("\n\t\t输入无效，请重新输入！");
			printf("\n\n\t\t");
			system("pause");
		}
	}
}

void MenuStaffChange(struct Node *phead)/*员工管理修改操作菜单*/
{
	int flagMenu = 0;/*菜单循环结束控制器*/
	char option[20];
	
	while (flagMenu == 0)
	{
		fflush(stdin);
		system("cls");
		printf("\n\t\t----------------修改员工信息----------------");
		printf("\n\t\t 按1通过查找 [员工编号] 进行修改信息操作");
		printf("\n\t\t 按2通过查找 [员工名称] 进行修改信息操作");
		printf("\n\t\t 按0返回 [员工管理] 菜单");
		printf("\n\t\t--------------------------------------------");
		
		char confirm[10];		/*确定：判断是否为误操作*/
		int num;
		struct Node *p = NULL;
		struct Node *pnew = (struct Node *)malloc(sizeof(struct Node));
		
		p = phead->next;
		pnew->data = NULL;		
		
		printf("\n\t\t请输入(0 - 2):");
		gets(option);
		
		if (strcmp(option, "0") == 0)
		{
			printf("\n\t\t退出修改员工信息功能！");
			flagMenu = 1;
			printf("\n\n\t\t");
			system("pause");
		}
		else if (strcmp(option, "1") == 1)
		{
			char varNo[CAPACITY];
				
			printf("\n\t\t输入 [员工编号]:");
			scanf("%s", varNo);
					
			while (p != NULL)
			{
				num = CompareStaNo(p->data, varNo);
					
				if (num == 0)
				{
					break;
				}
							
				p = p->next;
			}
						
			if (p != NULL)
			{
				printf("\n\t\t成功通过 [员工编号] 查找到该员工，接下来进行修改操作！\n");
				printf("\n\t\t是否确定修改该员工信息:");
				printf("\n\t\t按n或N退出修改操作，按其他键确定修改操作\n\t\t请输入：");
				fflush(stdin);
				gets(confirm);
				
				if (strcmp(confirm, "n")==0 || strcmp(confirm, "N")==0)
				{
					printf("\n\n\t\t退出修改操作！\n\t\t");
					system("pause");
					break;
				}
				else
				{
					pnew->data = InputSta();
					pnew->next = NULL;
								
					printf("\n\t\t修改后：\n");
					Change(phead, pnew, varNo, CompareStaNo);
					Traversal(phead, ShowSta);
							
					printf("\n\t\t修改完成！");
					printf("\n\n\t\t");
					system("pause");
				}
			}
			else 
			{
				printf("\n\t\t未找到该员工！");
				printf("\n\t\t请重新选择操作！");
				printf("\n\n\t\t");
				system("pause");
			}	
		}
		else if (strcmp(option, "2") == 0)
		{
			char varName[CAPACITY];
						
			printf("\n\t\t输入 [员工名称]:");
			scanf("%s", varName);
						
			while (p != NULL)
			{
				num = CompareStaName(p->data, varName);
							
				if (num == 0)
				{
					break;
				}
							
				p = p->next;
			}
						
			if (p != NULL)
			{
				printf("\n\t\t成功通过 [员工名称] 查找到该员工，接下来进行修改操作！\n");
				printf("\n\t\t是否确定修改该员工信息:");
				printf("\n\t\t按n或N退出修改操作，按其他键确定修改操作\n\t\t请输入：");
				fflush(stdin);
				gets(confirm);
				
				if (strcmp(confirm, "n")==0 || strcmp(confirm, "N")==0)
				{
					printf("\n\n\t\t退出修改操作！\n\t\t");
					system("pause");
					break;
				}
				else
				{
					pnew->data = InputSta();
					pnew->next = NULL;
								
					printf("\n\t\t修改后：\n");
					Change(phead, pnew, varName, CompareStaName);
					Traversal(phead, ShowSta);
							
					printf("\n\t\t修改完成！");
					printf("\n\n\t\t");
					system("pause");
				}
			}
			else 
			{
				printf("\n\t\t未找到该员工！");
				printf("\n\t\t请重新选择操作！");
				printf("\n\n\t\t");
				system("pause");
			}
		}
		else 
		{
			printf("\n\t\t输入无效，请重新输入！");
			printf("\n\n\t\t");
			system("pause");
		}
	}
}

void MenuStaffDelete(struct Node *phead)/*员工管理删除操作菜单*/
{
	int flagMenu = 0;/*菜单循环结束控制器*/
	char option[20];
	
	while (flagMenu == 0)
	{
		fflush(stdin);
		system("cls");
		printf("\n\t\t----------------删除员工信息----------------");
		printf("\n\t\t 按1通过查找 [员工编号] 进行删除信息操作");
		printf("\n\t\t 按2通过查找 [员工名称] 进行删除信息操作");
		printf("\n\t\t 按0返回 [员工管理] 菜单");
		printf("\n\t\t--------------------------------------------");
		
		char confirm[10];		/*确定：判断是否为误操作*/
		int num;
		struct Node *p = NULL;
		struct Node *q = (struct Node *)malloc(sizeof(struct Node));
		
		p = phead->next;
		q->data = NULL;
		
		printf("\n\t\t请输入(0 - 3):");
		gets(option);
		
		if (strcmp(option, "0") == 0)
		{
			printf("\n\t\t退出删除商品信息功能！");
			flagMenu = 1;
			printf("\n\n\t\t");
			system("pause");
		}
		else if (strcmp(option, "1") == 0)
		{
			char varNo[CAPACITY];
						
			printf("\n\t\t输入 [员工编号]:");
			scanf("%s", varNo);
						
			while (p != NULL)
			{
				num = CompareStaNo(p->data, varNo);
							
				if (num == 0)
				{
					break;
				}
							
				p = p->next;
			}
						
			if (p != NULL)
			{
				printf("\n\t\t成功通过 [员工编号] 查找到该商品，接下来进行删除操作！\n");
				printf("\n\t\t是否确定删除该员工信息:");
				printf("\n\t\t按n或N退出删除操作，按其他键确定删除操作\n\t\t请输入：");
				fflush(stdin);
				gets(confirm);
				
				if (strcmp(confirm, "n")==0 || strcmp(confirm, "N")==0)
				{
					printf("\n\n\t\t退出删除操作！\n\t\t");
					system("pause");
					break;
				}
				else
				{	
					q = Delete(phead, varNo, CompareStaNo);
					printf("\n\t\t被删除的数据：\n");
					ShowSta(q->data);
							
					printf("\n\t\t删除后：\n");
					Traversal(phead, ShowSta);
							
					printf("\n\t\t删除完成！");
					printf("\n\n\t\t");
					system("pause");
				}
			}
			else 
			{
				printf("\n\t\t未找到该员工！");
				printf("\n\t\t请重新选择操作！");
				printf("\n\n\t\t");
				system("pause");
			}	
		}
		else if (strcmp(option, "2") == 0)
		{
			char varName[CAPACITY];
						
			printf("\n\t\t输入 [员工名称]:");
			scanf("%s", varName);
						
			while (p != NULL)
			{
				num = CompareStaName(p->data, varName);
						
				if (num == 0)
				{
					break;
				}
							
				p = p->next;
			}
						
			if (p != NULL)
			{
				printf("\n\t\t成功通过 [员工名称] 查找到该员工，接下来进行删除操作！\n");
				printf("\n\t\t是否确定删除该员工信息:");
				printf("\n\t\t按n或N退出删除操作，按其他键确定删除操作\n\t\t请输入：");
				fflush(stdin);
				gets(confirm);
				
				if (strcmp(confirm, "n")==0 || strcmp(confirm, "N")==0)
				{
					printf("\n\n\t\t退出删除操作！\n\t\t");
					system("pause");
					break;
				}
				else
				{
					q = Delete(phead, varName, CompareStaName);
					printf("\n\t\t被删除的数据：\n");
					ShowSta(q->data);
							
					printf("\n\t\t删除后：\n");
					Traversal(phead, ShowSta);
							
					printf("\n\t\t删除完成！");
					printf("\n\n\t\t");
					system("pause");
				}
			}
			else 
			{
				printf("\n\t\t未找到该员工！");
				printf("\n\t\t请重新选择操作！");
				printf("\n\n\t\t");
				system("pause");
			}
		}
		else
		{
			printf("\n\t\t输入无效，请重新输入！");
			printf("\n\n\t\t");
			system("pause");
		}
	}
}

/*采购管理操作菜单*/
void MenuPurchase(struct Node *comPhead, struct Node *staPhead, struct Node *masterPurPhead, struct Node *detailPurPhead)	
{
	int flagMenu = 0;/*菜单循环结束控制器*/
	char option[20];
	
	while (flagMenu == 0)
	{
		fflush(stdin);
		system("cls");
		printf("\n\t\t------------------[采购管理]----------------------");
		printf("\n\t\t\t\t1 、[主表数据操作] 菜单");
		printf("\n\t\t\t\t2 、[明细数据操作] 菜单");
		printf("\n\t\t\t\t0 、返回[管理员用户]菜单");
		printf("\n\t\t--------------------------------------------------");	
		
		printf("\n\t\t请输入(0 - 2):");
		gets(option);
			
		if (strcmp(option, "0") == 0)
		{
			printf("\n\t\t返回 [管理员用户] 菜单！");
			flagMenu = 1;
			printf("\n\n\t\t");
			system("pause");
		}
		else if (strcmp(option, "1") == 0)
		{
			MenuMasterPurchase(staPhead, masterPurPhead);	/*主表数据操作菜单*/
		}
		else if (strcmp(option, "2") == 0)
		{
			MenuDetailPurchase(comPhead, masterPurPhead, detailPurPhead);	/*细表数据操作菜单*/
		}
		else
		{
			printf("\n\t\t输入无效，请重新输入！");
			printf("\n\n\t\t");
			system("pause");
		}
	}
}

void MenuMasterPurchase(struct Node *staPhead, struct Node *masterPurPhead)	/*主表数据操作菜单*/
{
	int flagMenu = 0;/*菜单循环结束控制器*/
	char option[20];
	
	while(flagMenu == 0)
	{
		fflush(stdin);
		system("cls");
		printf("\n\t\t----------------[主表数据操作]--------------------");
		printf("\n\t\t\t\t1 、录入主表数据");
		printf("\n\t\t\t\t2 、查询主表信息");
		printf("\n\t\t\t\t3 、通过采购清单号修改主表信息");
		printf("\n\t\t\t\t4 、通过采购清单号删除主表信息");
		printf("\n\t\t\t\t0 、返回 [采购管理] 菜单");
		printf("\n\t\t--------------------------------------------------");
		
		printf("\n\t\t请输入(0 - 4):");
		gets(option);
		
		if (strcmp(option, "0") == 0)
		{
			printf("\n\t\t返回 [采购管理] 菜单！");
			flagMenu = 1;
			printf("\n\n\t\t");
			system("pause");
		}
		else if (strcmp(option, "1") == 0)
		{
			char judge[10];		/*判断是否继续输入*/
			
			while (1)
			{
				fflush(stdin);
				printf("\n\t\t提示：输入n或N结束输入，按其他键则继续输入...");					
				gets(judge);
						
				if (strcmp(judge, "n")==0 || strcmp(judge, "N")==0)
				{
					printf("\n\t\t输入完成!\n\t\t");
					system("pause");
					break;
				}
				else
				{
					struct Node *pStore = (struct Node *)malloc(sizeof(struct Node));
					struct Node *q = NULL;
					int flag = 0;	/*判断外码和主码是否一致*/
					
					pStore->data = InputMasterPur();	/*输入主表数据信息*/
					q = staPhead->next;
					
					while(q != NULL)
					{
						int num = CompareOuterStaNo(q->data, pStore->data);		/*比较员工编号和采购主表的员工编号是否一致*/
						
						if (num == 0)
						{
							struct Node *ptail = FindTail(masterPurPhead);
	
							pStore->next = NULL;
							ptail->next = pStore;
							
							flag = 1;
							break;
						}
						
						q = q->next;
					}
					
					if (flag == 0)
					{
						printf("\n\t\t输入的员工编号在数据库中查找不到！");
						printf("\n\t\t此次输入录入失败！\n\t\t");
						free(pStore);
						system("pause");
					}
				}
			}
		}
		else if (strcmp(option, "2") == 0)
		{
			Traversal(masterPurPhead, ShowMasterPur);	
			printf("\n\n\t\t");
			system("pause");
		}
		else if (strcmp(option, "3") == 0)/*采购主表信息修改操作*/
		{
			char confirm[10];/*确定：判断是否为误操作*/
			struct Node *p = NULL;
			char varNo[CAPACITY];
			
			p = masterPurPhead->next;		
			printf("\n\t\t输入 [采购清单号]:");
			scanf("%s", varNo);
			
			/*判断在采购主表中手动输入的 [采购清单号] 是否存在*/		
			while (p != NULL)
			{
				int num = CompareMasterPurNo(p->data, varNo);
							
				if (num == 0)
				{
					break;
				}
							
				p = p->next;
			}
			
			/* [采购清单号] 存在*/	
			if (p != NULL)
			{
				printf("\n\t\t成功通过 [采购清单号] 查找到该采购信息，接下来进行修改操作！\n");
				printf("\n\t\t是否确定修改该采购信息:");
				printf("\n\t\t按n或N退出修改操作，按其他键确定修改操作\n\t\t请输入：");
				fflush(stdin);
				gets(confirm);
				
				while (1)
				{
					if (strcmp(confirm, "n")==0 || strcmp(confirm, "N")==0)
					{
						printf("\n\n\t\t退出修改操作！\n\t\t");
						system("pause");
						break;
					}
					else
					{
						struct Node *pStore = (struct Node *)malloc(sizeof(struct Node)); /*存储输入的采购主表数据*/
						struct Node *q =NULL;	/*指向主码*/
						int flag = 0;	/*判断外码和主码是否一致*/
						
						pStore->data = InputMasterPur();	/*输入主表数据信息*/
						q = staPhead->next;
						
						/*比较员工编号和采购主表的员工编号是否一致*/
						while(q != NULL)
						{
							int num = CompareOuterStaNo(q->data, pStore->data);		
							
							if (num == 0)
							{
								flag = 1;
								break;
							}
							
							q = q->next;
						}
						
						/*若不一致则退出，需要重新选择*/
						if (flag == 0)
						{
							printf("\n\t\t输入的员工编号在数据库中查找不到！");
							printf("\n\t\t修改失败！\n\t\t");
							free(pStore);
							system("pause");
							break;
						}
						
						/*若一致，则修改*/
						printf("\n\t\t修改后：\n");
						Change(masterPurPhead, pStore, varNo, CompareMasterPurNo);
						Traversal(masterPurPhead, ShowMasterPur);
						
						/*提示修改完成*/
						printf("\n\t\t修改完成！");
						printf("\n\n\t\t");
						system("pause");
						break;
					}
				}
			}
			else /* [采购清单号] 不存在*/
			{
				printf("\n\t\t未找到该采购信息！");
				printf("\n\t\t请重新选择操作！");
				printf("\n\n\t\t");
				system("pause");
			}	
		}
		else if (strcmp(option, "4") == 0)
		{
			char confirm[10];/*确定：判断是否为误操作*/
			struct Node *p = NULL;
			char varNo[CAPACITY];
			struct Node *q = (struct Node *)malloc(sizeof(struct Node));
		
			q->data = NULL;
			p = masterPurPhead->next;
					
			printf("\n\t\t输入 [采购清单号]:");
			scanf("%s", varNo);
						
			while (p != NULL)
			{
				int num = CompareMasterPurNo(p->data, varNo);
							
				if (num == 0)
				{
					break;
				}
							
				p = p->next;
			}
						
			if (p != NULL)
			{
				printf("\n\t\t成功通过 [采购清单号] 查找到该采购信息，接下来进行删除操作！\n");
				printf("\n\t\t是否确定删除该采购信息:");
				printf("\n\t\t按n或N退出删除操作，按其他键确定删除操作\n\t\t请输入：");
				fflush(stdin);
				gets(confirm);
				
				if (strcmp(confirm, "n")==0 || strcmp(confirm, "N")==0)
				{
					printf("\n\n\t\t退出删除操作！\n\t\t");
					system("pause");
				}
				else
				{	
					q = Delete(masterPurPhead, varNo, CompareMasterPurNo);
					printf("\n\t\t被删除的数据：\n");
					ShowMasterPur(q->data);
							
					printf("\n\t\t删除后：\n");
					Traversal(masterPurPhead, ShowMasterPur);
							
					printf("\n\t\t删除完成！");
					printf("\n\n\t\t");
					system("pause");
				}
			}	
			else 
			{
				printf("\n\t\t未找到该采购信息！");
				printf("\n\t\t请重新选择操作！");
				printf("\n\n\t\t");
				system("pause");
			}
		}
		else 
		{
			printf("\n\t\t输入无效，请重新输入！");
			printf("\n\n\t\t");
			system("pause");
		}
	}
}

void MenuDetailPurchase(struct Node *comPhead, struct Node *masterPurPhead, struct Node *detailPurPhead)	/*细表数据操作菜单*/
{
	int flagMenu = 0;/*菜单循环结束控制器*/
	char option[20];
	
	while(flagMenu == 0)
	{
		fflush(stdin);
		system("cls");
		printf("\n\t\t----------------[细表数据操作]--------------------");
		printf("\n\t\t\t\t1 、录入细表数据");
		printf("\n\t\t\t\t2 、查询细表信息");
		printf("\n\t\t\t\t3 、通过采购明细号修改细表信息");
		printf("\n\t\t\t\t4 、通过采购明细号删除细表信息");
		printf("\n\t\t\t\t0 、返回 [采购管理] 菜单");
		printf("\n\t\t--------------------------------------------------");
		
		printf("\n\t\t请输入(0 - 4):");
		gets(option);
		
		if (strcmp(option, "0") == 0)
		{
			printf("\n\t\t返回 [采购管理] 菜单！");
			flagMenu = 1;
			printf("\n\n\t\t");
			system("pause");
		}
		else if (strcmp(option, "1") == 0)
		{
			char judge[10];		/*判断是否继续输入*/
			
			while (1)
			{
				fflush(stdin);
				printf("\n\t\t提示：输入n或N结束输入，按其他键则继续输入...");					
				gets(judge);
						
				if (strcmp(judge, "n")==0 || strcmp(judge, "N")==0)
				{
					printf("\n\t\t输入完成!\n\t\t");
					system("pause");
					break;
				}
				else
				{
					struct Node *pStore = (struct Node *)malloc(sizeof(struct Node));
					struct Node *q = NULL;
					struct Node *r = NULL;
					int flag = 0;		/*判断外码和主码是否一致*/
					
					q = comPhead->next; 	/*用于判断商品编号与采购细表的商品编号是否一致*/
					r = masterPurPhead->next; 	/*用于比较采购清单号和采购细表的采购清单号是否一致*/
					
					pStore->data = InputDetailPur();	/*输入细表数据信息*/
					
					while(q!=NULL || r!=NULL)
					{
						int numCom = CompareOuterComNo(q->data, pStore->data);	/*比较商品编号和采购细表的商品编号是否一致*/
						int numMasterPur = CompareOuterMasterPurNo(r->data, pStore->data); /*比较采购清单号和采购细表的采购清单号是否一致*/
						
						if (numCom==0 && numMasterPur==0) 
						{
							struct Node *ptail = FindTail(detailPurPhead);
	
							pStore->next = NULL;
							ptail->next = pStore;
							
							flag = 1;
							break;
						}
						
						if (numCom != 0)
						{
							q = q->next;
						}
						if (numMasterPur != 0)
						{
							r = r->next;
						}	
					}
					
					if (flag == 0)
					{
						printf("\n\t\t输入的商品编号或采购清单号在数据库中查找不到！");
						printf("\n\t\t此次输入录入失败！\n\t\t");
						free(pStore);
						system("pause");
					}
				}
			}
		}
		else if (strcmp(option, "2") == 0)
		{
			Traversal(detailPurPhead, ShowDetailPur);	
			printf("\n\n\t\t");
			system("pause");
		}
		else if (strcmp(option, "3") == 0)/*采购细表信息修改操作*/
		{
			char confirm[10];/*确定：判断是否为误操作*/
			struct Node *p = NULL;
			char varNo[CAPACITY];
			
			p = detailPurPhead->next;		
			printf("\n\t\t输入 [采购明细号]:");
			scanf("%s", varNo);
			
			/*判断在采购细表中手动输入的 [采购明细号] 是否存在*/		
			while (p != NULL)
			{
				int num = CompareDetailPurNo(p->data, varNo);
							
				if (num == 0)
				{
					break;
				}
							
				p = p->next;
			}
			
			/* [采购清单号] 存在*/	
			if (p != NULL)
			{
				printf("\n\t\t成功通过 [采购明细号] 查找到该采购信息，接下来进行修改操作！\n");
				printf("\n\t\t是否确定修改该采购信息:");
				printf("\n\t\t按n或N退出修改操作，按其他键确定修改操作\n\t\t请输入：");
				fflush(stdin);
				gets(confirm);
				
				while (1)
				{
					if (strcmp(confirm, "n")==0 || strcmp(confirm, "N")==0)
					{
						printf("\n\n\t\t退出修改操作！\n\t\t");
						system("pause");
						break;
					}
					else
					{
						struct Node *pStore = (struct Node *)malloc(sizeof(struct Node));
						struct Node *q = NULL;
						struct Node *r = NULL;
						int flag = 0;		/*判断外码和主码是否一致*/
						
						q = comPhead->next; 	/*用于判断商品编号与采购细表的商品编号是否一致*/
						r = masterPurPhead->next; 	/*用于比较采购清单号和采购细表的采购清单号是否一致*/
						
						pStore->data = InputDetailPur();	/*输入细表数据信息*/
						
						while(q!=NULL || r!=NULL)
						{
							int numCom = CompareOuterComNo(q->data, pStore->data);	/*比较商品编号和采购细表的商品编号是否一致*/
							int numMasterPur = CompareOuterMasterPurNo(r->data, pStore->data); /*比较采购清单号和采购细表的采购清单号是否一致*/
							
							if (numCom==0 && numMasterPur==0) 
							{
								flag = 1;
								break;
							}
							
							if (numCom != 0)
							{
								q = q->next;
							}
							if (numMasterPur != 0)
							{
								r = r->next;
							}	
						}
						
						if (flag == 0)
						{
							printf("\n\t\t输入的商品编号或采购清单号在数据库中查找不到！");
							printf("\n\t\t此次输入录入失败！\n\t\t");
							free(pStore);
							system("pause");
							break;
						}
						else
						{
							/*若一致，则修改*/
							printf("\n\t\t修改后：\n");
							Change(detailPurPhead, pStore, varNo, CompareDetailPurNo);
							Traversal(detailPurPhead, ShowDetailPur);
							
							/*提示修改完成*/
							printf("\n\t\t修改完成！");
							printf("\n\n\t\t");
							system("pause");
							break;
						}
					}
				}
			}
			else 
			{
				printf("\n\t\t未找到该采购信息！");
				printf("\n\t\t请重新选择操作！");
				printf("\n\n\t\t");
				system("pause");
			}	
		}
		else if (strcmp(option, "4") == 0)
		{
			char confirm[10];/*确定：判断是否为误操作*/
			struct Node *p = NULL;
			char varNo[CAPACITY];
			struct Node *q = (struct Node *)malloc(sizeof(struct Node));
		
			q->data = NULL;
			p = detailPurPhead->next;
					
			printf("\n\t\t输入 [采购明细号]:");
			scanf("%s", varNo);
						
			while (p != NULL)
			{
				int num = CompareDetailPurNo(p->data, varNo);
							
				if (num == 0)
				{
					break;
				}
							
				p = p->next;
			}
						
			if (p != NULL)
			{
				printf("\n\t\t成功通过 [采购明细号] 查找到该采购信息，接下来进行删除操作！\n");
				printf("\n\t\t是否确定删除该采购信息:");
				printf("\n\t\t按n或N退出删除操作，按其他键确定删除操作\n\t\t请输入：");
				fflush(stdin);
				gets(confirm);
				
				if (strcmp(confirm, "n")==0 || strcmp(confirm, "N")==0)
				{
					printf("\n\n\t\t退出删除操作！\n\t\t");
					system("pause");
				}
				else
				{	
					q = Delete(detailPurPhead, varNo, CompareDetailPurNo);
					printf("\n\t\t被删除的数据：\n");
					ShowDetailPur(q->data);
							
					printf("\n\t\t删除后：\n");
					Traversal(detailPurPhead, ShowDetailPur);
							
					printf("\n\t\t删除完成！");
					printf("\n\n\t\t");
					system("pause");
				}
			}	
			else 
			{
				printf("\n\t\t未找到该采购信息！");
				printf("\n\t\t请重新选择操作！");
				printf("\n\n\t\t");
				system("pause");
			}
		}
		else 
		{
			printf("\n\t\t输入无效，请重新输入！");
			printf("\n\n\t\t");
			system("pause");
		}
	}
}

/*普通用户操作菜单*/
void MenuPerson(sta *pSta, struct Node *staPhead, struct Node *comPhead, struct Node *masterPurPhead, struct Node *detailPurPhead)
{
	int flagMenu = 0;/*菜单循环结束控制器*/
	char option[20];
	
	while (flagMenu == 0)
	{
		fflush(stdin);
		system("cls");
		printf("\n\t\t-------------------[普通用户]---------------------");
		printf("\n\t\t\t\t1 、查询个人信息");
		printf("\n\t\t\t\t2 、查询所有商品信息");
		printf("\n\t\t\t\t3 、查询所有采购信息");
		printf("\n\t\t\t\t0 、返回 [超市进存销管理系统] ");
		printf("\n\t\t--------------------------------------------------");	
		
		
		printf("\n\t\t请输入(0-3):");
		gets(option);
			
		
		if (strcmp(option, "0") == 0)
		{
			printf("\n\t\t返回 [超市进存销管理系统] ！");
			flagMenu = 1;
			printf("\n\n\t\t");
			system("pause");
		}
		else if (strcmp(option, "1") == 0)
		{
			int flag = 0;
			struct Node *q = NULL;
			q = staPhead->next;
			
			while (flag == 0) /*在员工链表中一定能找到pSta->staNo,因此不需要用q != NULL*/
			{
				if (CompareStaNo(q->data, pSta->staNo) == 0)
				{
					flag = 1;
					break;
				}
				
				q = q->next;
			}
			
			printf("\n\t\t员工个人信息：");
			ShowSta(q->data);
			printf("\n\n\t\t");
			system("pause");
		}
		else if (strcmp(option, "2") == 0)
		{
			printf("\n\t\t商品信息：");
			Traversal(comPhead, ShowCom);	
			printf("\n\n\t\t");
			system("pause");
		}
		else if (strcmp(option, "3") == 0)
		{
			printf("\n\t\t采购主表信息：");
			Traversal(masterPurPhead, ShowMasterPur);	
			printf("\n\t\t---------------------------------------------\n");
			printf("\n\t\t采购明细信息：");
			Traversal(detailPurPhead, ShowDetailPur);	
			printf("\n\n\t\t");
			system("pause");
		}
		else
		{
			printf("\n\t\t输入无效，请重新输入！");
			printf("\n\n\t\t");
			system("pause");
		}
			
	}
}

sta *MenuPersonLogIn(struct Node *staPhead)	/*用户登录界面*/
{
	int flagMenu = 0;/*菜单循环结束控制器*/
	char option[20];
	
	
	while (flagMenu == 0)
	{
		fflush(stdin);
		system("cls");
		printf("\n\t\t-----------------[用户登录界面]-------------------");
		printf("\n\t\t\t\t1 、输入账号密码");
		printf("\n\t\t\t\t0 、返回 [普通用户] 菜单");
		printf("\n\t\t--------------------------------------------------");	
		
		printf("\n\t\t请输入(0-1):");
		gets(option);
		
		if  (strcmp(option, "0") == 0)
		{
			printf("\n\t\t返回 [普通用户] 菜单！");
			flagMenu = 1;
			printf("\n\n\t\t");
			system("pause");
		}
		else if (strcmp(option, "1") == 0)
		{	
			char judge[10];
			int flag = 0;
			
			while (flag == 0)
			{
				sta *pSta = (sta *)malloc(sizeof(sta));
				struct Node *q = staPhead->next;
				
				fflush(stdin);
				printf("\n\t\t提示：输入n或N结束输入，按其他键则继续输入...");					
				gets(judge);
						
				if (strcmp(judge, "n")==0 || strcmp(judge, "N")==0)
				{
				 	printf("\n\t\t退出 [用户登录] 操作！\n\n\t\t");
					system("pause");
					return NULL;
				}
				else
				{
					/*输入账号密码*/
					printf("\n\n\t\t账号(员工编号)：");
					scanf("%s", pSta->staNo);
					printf("\n\t\t员  工  密  码：");
					scanf("%s", pSta->staPassword);
					
					/*比对账号密码，判断是否有权限进入 [普通用户] 菜单*/
					while (q != NULL)
					{
						int numStaNo = CompareStaNo(q->data, pSta->staNo);
						int numStaPassword = CompareStaPassword(q->data, pSta->staPassword);
						
						if (numStaNo==0 && numStaPassword==0)
						{
							printf("\n\t\t登录成功！\n\t\t");
							flag = 1;
							system("pause");
							return pSta;
						}
						
						q = q->next;
					}
					
					if (q == NULL)
					{
						printf("\n\t\t账号或密码输入错误！");
						printf("\n\t\t无法进入 [普通用户] 菜单\n");
						free(pSta);
					}
				}
			}
		}
		else
		{
			printf("\n\t\t输入无效，请重新输入！");
			printf("\n\n\t\t");
			system("pause");
		}
	}
}

